<template>
  <div v-if="pageReady">
    <el-row>
      <el-col :span="9" v-if="!isMobile">1</el-col>
      <el-col :span="isMobile ? 24 : 6">
        <el-card>
          <div slot="header" class="clearfix">
            <span>访客审核</span>
          </div>
          <div>
            <p>访客姓名：{{fangKeRecord.visitorname}}</p>
            <p>访客手机号：{{fangKeRecord.phoneno}}</p>
            <p>拜访人：{{fangKeRecord.receptionistname}}</p>
            <p>拜访原因：{{fangKeRecord.visitpurpose}}</p>
            <p>拜访日期：<DateFormat :value="fangKeRecord.visitstarttime" :format="'YYYY-MM-DD'"></DateFormat></p>
            <p>
              <el-button size="mini" type="success" @click="shenHe(1)">通过</el-button>
              <el-button size="mini" type="danger" @click="shenHe(0)">拒绝</el-button>
            </p>
          </div>
        </el-card>
      </el-col>
      <el-col :span="9" v-if="!isMobile"></el-col>
    </el-row>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      id : '',
      isMobile : false,
      fangKeRecord:{},
      pageReady : false
    }
  },
  mounted() {
    this.checkDeviceType();
    this.getFangKeRecord();
  },
  methods: {
    checkDeviceType() {
      const viewportWidth = window.innerWidth;
      this.isMobile = viewportWidth < 768;
    },
    getFangKeRecord(){
      this.id = this.$route.query.id
      console.log(this.id)
      request({
        url: '/fangke/getfangkerecord',
        data: {id : this.id}
      }).then(res => {
        const { code, msg, data } = res
        if(code === '200'){
          this.fangKeRecord = data
          this.pageReady = true
        }
      }).catch(catcherr  => {
        console.log(catcherr)
        setTimeout(()=>{
          window.close()
        },1000)
      })
    },
    shenHe(status){
      request({
        url: '/fangke/shenhefangkerecord',
        data: {id : this.id, statusId : status}
      }).then(res => {
        const {code} = res
        if(code === '200'){
          this.$message.success("审核通过")
          setTimeout(()=>{
            window.close()
          },1000)
        }
      })
    }
  },
}
</script>

<style scoped>

</style>
